const fs = require('fs');
const turf = require('@turf/turf');
const path = require('path');
const { execSync } = require('child_process');

// 1. 读取原始数据
const raw = JSON.parse(fs.readFileSync(path.join(__dirname, 'bianjiepinghua.json')));

raw.forEach(item => {
  item.geometry.coordinates[0] =  turf.bezierSpline(turf.lineString(item.geometry.coordinates[0]), {
    resolution: 20000,
    sharpness: 0.5
  }).geometry.coordinates
});
fs.writeFileSync(path.join(__dirname, 'smoothed_result.json'), JSON.stringify(raw));







// // 2. 执行平滑处理 (带拓扑保持)
// const smoothed = turf.combine(raw.map(f => {

//   let bezier = turf.bezierSpline(turf.lineString(f.geometry.coordinates[0]), {
//     resolution: 20000,
//     sharpness: 0.5
//   })
//   return bezier
//   console.log('bezier', bezier)

//   let simplify = turf.simplify(bezier, { tolerance: 0.001, highQuality: true });
//   console.log('simplify', simplify)
//   return simplify

// }));

// // 3. 生成结果文件
// fs.writeFileSync(path.join(__dirname, 'smoothed_result.json'), JSON.stringify(smoothed));